package community.hospital.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import community.hospital.annotation.Log;
import community.hospital.annotation.Module;
import community.hospital.annotation.NeedLogin;
import community.hospital.annotation.NeedPermission;
import community.hospital.common.Add;
import community.hospital.common.BaseRemove;
import community.hospital.common.R;
import community.hospital.common.Update;
import community.hospital.entity.request.ScheduleRequest;
import community.hospital.entity.request.ListScheduleRequest;
import community.hospital.entity.response.ScheduleResponse;
import community.hospital.service.application.ScheduleApplicationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static community.hospital.common.Constant.*;
import static community.hospital.common.PermissionConstant.*;

/**
 * @author yindingjie
 */
@RestController
@RequestMapping("/schedule")
@Module("排班")
public class ScheduleController {

    @Resource
    private ScheduleApplicationService scheduleApplicationService;
    @PostMapping("/query/{id}")
    @Log(methodName = LOG_QUERY,desc = "查询排班")
    public R<ScheduleResponse> querySchedule(@PathVariable Long id) {
        ScheduleResponse scheduleResponse = scheduleApplicationService.querySchedule(id);
        return R.ok(scheduleResponse);
    }

    @PostMapping("/listSchedule")
    @Log(methodName = LOG_QUERY,desc = "分页查询排班")
    public R<Page<ScheduleResponse>> listSchedule(@Valid @RequestBody ListScheduleRequest request) {
        Page<ScheduleResponse> responsePage = scheduleApplicationService.listSchedule(request);
        return R.ok(responsePage);
    }
    @Log(methodName = LOG_INSERT,desc = "新增排班")
    @PostMapping("/addSchedule")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN, permission = ADD_SCHEDULE)
    public R<Boolean> addSchedule(@Validated(Add.class) @RequestBody ScheduleRequest request) {

        Boolean isOk = scheduleApplicationService.addOrUpdateSchedule(request);
        return R.ok(isOk);
    }
    @Log(methodName = LOG_REMOVE,desc = "删除排班")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN,permission = REMOVE_SCHEDULE)
    @PostMapping("/removeSchedule")
    public R<Boolean> removeSchedule(@Valid @RequestBody BaseRemove baseRemove) {
        Boolean isOk = scheduleApplicationService.removeSchedule(baseRemove.getIds());
        return R.ok(isOk);
    }
    @Log(methodName = LOG_UPDATE,desc = "更新排班")
    @NeedLogin
    @NeedPermission(role = SUPER_ADMIN,permission = UPDATE_SCHEDULE)
    @PostMapping("/updateSchedule")
    public R<Boolean> updateSchedule(@Validated(Update.class) @RequestBody ScheduleRequest request) {
        Boolean isOk = scheduleApplicationService.addOrUpdateSchedule(request);
        return R.ok(isOk);
    }
    
    

}
